#include "ServerServerMsgs.h"


void ElectionMsg::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	ss<<id<<' ';
	senderInfo.serialize(ss);
}

void ElectionMsg::deSerialize(std::stringstream & ss)
{
	Message::deSerialize(ss);
	ss>>id;
	senderInfo.deSerialize(ss);
}

void Elected::serialize(std::stringstream & ss )
{
	Message::serialize(ss);
	cordinatorInfo.serialize(ss);
}

void Elected::deSerialize(std::stringstream & ss)
{
	Message::deSerialize(ss);
	cordinatorInfo.deSerialize(ss);
}

void ElectedRet::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	ss<<numberOfTasks<<' ';
	ss<<taskInfoList.size()<<' ';
	std::list<TaskInfo>::iterator it;
	for( it = taskInfoList.begin(); it != taskInfoList.end();it++)
		it->serialize(ss);

}

void ElectedRet::deSerialize(std::stringstream & ss)
{
	taskInfoList.clear();
	TaskInfo taskInfo;
	ss>>numberOfTasks;
	int listSize;
	ss>>listSize;

	for(int i=0; i<listSize; i++)
	{
		taskInfo.deSerialize(ss);
		taskInfoList.push_front(taskInfo);
	}
}

void Registration::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	serverInfo.serialize(ss);
}


void Registration::deSerialize(std::stringstream & ss)
{
	serverInfo.deSerialize(ss);
}

void RegistrationRet::serialize(std::stringstream & ss)
{
	Message::serialize(ss);
	ss<<accepted<<' ';
	ss<<serverList.size()<<' ';
	std::list<ServerInfo>::iterator it;
	for( it = serverList.begin(); it != serverList.end();it++)
		it->serialize(ss);
	serverName.serialize(ss);

}

void RegistrationRet::deSerialize(std::stringstream & ss)
{
	ss>>accepted;
	int listSize;
	ss>>listSize;
	ServerInfo serverInfo;
	for(int i=0; i<listSize; i++)
	{
		serverInfo.deSerialize(ss);
		serverList.push_front(serverInfo);
	}

	serverName.deSerialize(ss);

}